import { Config, Inject, Provide } from '@midwayjs/decorator';
import { BaseService, CoolCommException } from '@cool-midway/core';
import { BizCustomerListEntity } from '../../bizCustomer/entity/list';
import { BizWorkerListEntity } from '../../bizWorker/entity/list';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';

/**
 * 公共服务
 */
@Provide()
export class BizCommonBaseService extends BaseService {
  @InjectEntityModel(BizCustomerListEntity)
  bizCustomerListEntity: Repository<BizCustomerListEntity>;

  @InjectEntityModel(BizWorkerListEntity)
  bizWorkerListEntity: Repository<BizWorkerListEntity>;

  /**
   * 获取基本信息
   * @param userId 客户id
   */
  async getBaseInf(userId: number) {
    const userInfo = await this.bizCustomerListEntity.findOneBy({ id: userId });

    if (userInfo) {
      delete userInfo.createTime;
      delete userInfo.updateTime;
      delete userInfo.status;
      delete userInfo.wechatOpenId;
    }

    return {
      userInfo,
    };
  }

  /**
   * 获取师傅基本信息
   * @param userId 师傅id
   */
  async getWorkerBaseInf(userId: number) {
    const userInfo = await this.bizWorkerListEntity.findOneBy({ id: userId });

    if (userInfo) {
      delete userInfo.createTime;
      delete userInfo.updateTime;
      delete userInfo.status;
      delete userInfo.wechatOpenId;
      delete userInfo.password;
    }

    return {
      userInfo,
    };
  }

  getWorkTypeDeposit(workType: number) {
    switch (workType) {
      case 0: {
        // 电工
        return 0.02;
        return 200;
      }
      case 1: {
        // 砖工
        return 0.03;
        return 300;
      }
      case 2: {
        // 漆工
        return 0.05;
        return 500;
      }
      default: {
        return 0;
      }
    }
  }
}
